
layui.use(['form', 'xmSelect', 'upload', 'laydate','table'], function () {
    var form = layui.form;
    var layer = layui.layer,myInviteeId='',myInviteeList=[],pages=0
    var xmSelect = layui.xmSelect,laydate = layui.laydate

    getSalaryList('#salary',form)
    $('#projectId').attr("disabled", true);
    AjaxGet('/userAunt/seleProject').then(function (response){
        //设置select
        $('#projectId').empty();
        $('#projectId').append($('<option>', {
            value: '',
            text: '请选择工作类型'
        }))
        response.data.forEach(item => {
            $('#projectId').append($('<option>', {
                value: item.id,
                text: item.name,
                selected: item.id == $('#projectIdValue').val()
            }))
        })
        $('#projectId').attr("disabled", $('#infoType').val() == 'infor');
        form.render('select');

    }).catch(function (error){
        layer.msg(error.msg)
    })
    const getThisTime=(data=null)=>{
        if(null==data){
            data=new Date()
        }
        return data.getFullYear()+'-'+(data.getMonth()>9?(data.getMonth()+1):('0'+(data.getMonth()+1)))+'-'+data.getDate()+' '+data.getHours()+':00:00'
    }
    const getMaxDate=(data1,data2)=>{
        let olddata1=new Date(data1),olddata2=new Date(data2)
        return olddata1>olddata2?data2:data1
    }
    laydate.render({
        elem: '#ID-laydate-range',
        range: ['#createTime', '#endTime'],
        rangeLinked: true,
        type: 'datetime',
        min:$('#infoType').val()=='edit'?getMaxDate($('#createTime').val(),getThisTime()):getThisTime(),
        shortcuts: [
            {
                text: "上个月",
                value: function () {
                    var date = new Date();
                    var year = date.getFullYear();
                    var month = date.getMonth();
                    return [
                        new Date(year, month - 1, 1),
                        new Date(year, month, 0)
                    ];
                }
            }, {
                text: "这个月",
                value: function () {
                    var date = new Date();
                    var year = date.getFullYear();
                    var month = date.getMonth();
                    return [
                        new Date(year, month, 1),
                        new Date(year, month + 1, 0)
                    ];
                }
            },
            {
                text: "下个月",
                value: function () {
                    var date = new Date();
                    var year = date.getFullYear();
                    var month = date.getMonth();
                    return [
                        new Date(year, month + 1, 1),
                        new Date(year, month + 2, 0)
                    ];
                }
            }
        ],
        done: function (value, date, endDate) {
            let mydataList = value.split(' - ')
             console.log(mydataList)
        }
    });




    //提交事件
    form.on('submit(submit)', function (data) {
        let myParams={...data.field},MyUrl=''
        console.log(myParams)
        if('add'==$('#infoType').val()){
            MyUrl='/userDemand/backgroundSave'
        }else if('edit'==$('#infoType').val()) {
            MyUrl='/userDemand/backgroundUpdate'
            myParams.id=$('#userId').val()
        }else{
            var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
            parent.layer.close(index);
            parent.load();
            return false
        }
        AjaxPost(MyUrl, myParams).then(function (response) {
            parent.layer.msg("操作成功");
            var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
            parent.layer.close(index);
            parent.load();
        }).catch(error => {
            layer.msg(error.msg)
        })


    });

});


